<%@ page language="java" trimDirectiveWhitespaces="true" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@page import="java.io.File , javax.servlet.http.HttpServletRequest"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@page isErrorPage="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Download Page</title>
</head>
<body>
<%
try{
	Object filePath =request.getAttribute("destFilepath");
	Object fileName =request.getAttribute("destFileName");
	File file = new File(filePath.toString());  
    ServletContext ctx = getServletContext();
 	String mimeType = ctx.getMimeType(file.getAbsolutePath());
 	response.reset();
	response.setHeader("Cache-Control","private");
    response.setHeader("Pragma","expires");
		response.setHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");
		response.setContentType(mimeType != null? mimeType:"application/octet-stream");
		response.setHeader("Content-Length", String.valueOf(file.length()));
 	java.io.FileInputStream fileInputStream = new java.io.FileInputStream(file);
	ServletOutputStream os = response.getOutputStream();
    byte[] bufferData = new byte[4096];
	while(fileInputStream.read(bufferData, 0, 4096) != -1) {
			os.write(bufferData, 0, 4096); 
		} 
		fileInputStream.close();  
		os.flush();
		os.close();
		out.clear(); // where out is a JspWriter
		out = pageContext.pushBody();
		return;
    }catch(Exception e){
    	System.out.print("e");	    	
    }  
		
		
%> 
</body>
</html>

<!-- 

	try{
		Object filePath =request.getAttribute("destFilepath");
		Object fileName =request.getAttribute("destFileName");
		File file = new File(filePath.toString());  
	    ServletContext ctx = getServletContext();
	 	String mimeType = ctx.getMimeType(file.getAbsolutePath());
	 	response.reset();
		response.setHeader("Cache-Control","private");
        response.setHeader("Pragma","expires");
  		response.setHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");
  		response.setContentType(mimeType != null? mimeType:"application/octet-stream");
  		response.setHeader("Content-Length", String.valueOf(file.length()));
	 	java.io.FileInputStream fileInputStream = new java.io.FileInputStream(file);
		ServletOutputStream os = response.getOutputStream();
        byte[] bufferData = new byte[4096];
		while(fileInputStream.read(bufferData, 0, 4096) != -1) {
				os.write(bufferData, 0, 4096); 
			} 
			fileInputStream.close();  
			os.flush();
			os.close();
			out.clear(); // where out is a JspWriter
			out = pageContext.pushBody();
			return;
	    }catch(Exception e){
	    	System.out.print("e");	    	
	    }  		  
 

 -->